﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML.Graphics;
using SFML.Window;
using Theta.Components;

namespace Theta.Entities
{
    public class Entity : IUpdateable, IDrawable, IDisposable
    {
        ComponentContainer _ccontainer;

        public Entity()
        {
            _ccontainer = new ComponentContainer();
        }

        public void AddComponent<T>(params T[] component) where T : BaseComponent
        {
            foreach(T c in component)
            {
                if (c.Parent != null)
                    throw new ArgumentException("The component is already being used by another entity, create a new instance of the object and add that instead. Component type: " + typeof(T).FullName);
                _ccontainer.AddComponent(c);
                c.Parent = this;
            }
        }

        public T GetComponent<T>() where T : BaseComponent
        {
            return _ccontainer.GetComponent<T>();
        }

        public void RemoveComponent<T>() where T : BaseComponent
        {
            RemoveComponent<T>(false);
        }

        public void RemoveComponent<T>(bool dispose) where T : BaseComponent
        {
            _ccontainer.RemoveComponent<T>(dispose);
        }

        public virtual void Dispose()
        {
            _ccontainer.Dispose();
        }

        public void Update(TimeSpan elapsedTime)
        {
            _ccontainer.Update(elapsedTime);
        }

        public void Draw(RenderWindow renderWindow)
        {
            _ccontainer.Draw(renderWindow);
        }
    }
}
